<template>
  <el-dialog :visible.sync="visible" width="70%" custom-class="default-dialog"
    :close-on-click-modal="false" @close="cancel" append-to-body>
    <div slot="title">
      <img v-if="type" :src="require(`@/assets/img/${type}.png`)" alt="">
      <span>{{ title }} </span>
    </div>
    <el-form :model="form" ref="form" label-width="100px">
      <el-form-item label="用户名：" prop="name">
        <div>{{ form.userName }}</div>
      </el-form-item>
      <el-form-item label="访问服务：" prop="name">
        <div>{{ form.serviceName }}</div>
      </el-form-item>
      <el-form-item label="服务器地址：" prop="name">
        <div>{{ form.host }}</div>
      </el-form-item>
      <el-form-item label="访问地址：" prop="name">
        <div>{{ form.url }}</div>
      </el-form-item>
      <!-- <el-form-item label="方式：" prop="name">
        <div>{{ form.method }}</div>
      </el-form-item> -->
      <el-form-item label="耗时(ms)：" prop="name">
        <div>{{ form.elapsed }}</div>
      </el-form-item>
      <el-form-item label="浏览器：" prop="name">
        <div>{{ form.browser }}</div>
      </el-form-item>
      <el-form-item label="操作系统：" prop="name">
        <div>{{ form.os }}</div>
      </el-form-item>
      <el-form-item label="浏览器信息：" prop="name">
        <div>{{ form.browserInfo }}</div>
      </el-form-item>
      <el-form-item label="访问者IP地址：" prop="name">
        <div>{{ form.ipAddress }}</div>
      </el-form-item>
      <el-form-item label="请求参数：" prop="name">
        <json-viewer
          v-if="form.parameter"
          class="code-pre"
          :value="JSON.parse(form.parameter)"
          copyable
          @copied="copys"
        >
        <template slot="copy">
          <i class="el-icon-document-copy" title="复制"></i>
        </template>
        </json-viewer>
      </el-form-item>
      <el-form-item label="响应状态：" prop="name">
        <div>{{ form.reqStatus }}</div>
      </el-form-item>
      <el-form-item label="响应内容：" prop="name">
        <json-viewer
          v-if="form.reqMessage"
          class="code-pre"
          :value="JSON.parse(form.reqMessage)"
          copyable
          @copied="copys"
        >
        <template slot="copy">
          <i class="el-icon-document-copy" title="复制"></i>
        </template>
        </json-viewer>
      </el-form-item>
    </el-form>
    <span slot="footer">
      <el-button size="small" @click="cancel">取 消</el-button>
      <el-button size="small" type="primary" @click="sure">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import JsonViewer from 'vue-json-viewer'
   
export default {
  components:{ JsonViewer },
  data() {
    return {
      visible: false,
      title: '详情',
      form: {},
      type: 'view'
    };
  },
  methods: {
    showModal(row) {
      this.visible = true
     this.title = '详情'
     this.form = Object.assign({},row)
    //  this.form.parameter = JSON.parse(this.form.parameter)
    },
    // 复制
    copys(){
      this.$message.success('复制成功！')
    },
    sure() {
      this.visible = false;
      this.$refs['form'].validate(valid => {
        if (valid) {
        }
      });
    },
    cancel() {
      this.visible = false;
      this.$refs["form"].resetFields();
    },
  }
};
</script>
<style lang="less" scoped>
.code-pre{
  background: rgba(0,0,0,.1);
  overflow: hidden;
}
</style>
<style lang="less">
.jv-container .jv-code{
  padding: 8px 15px!important;
}
</style>
